package com.demo.security.access.audit;

/**
 * 审计模型
 * 
 * @author ryuu.kk
 */
public class AuditModel implements java.io.Serializable {
	
	/**
	 * 版本序列化ID
	 */
	private static final long serialVersionUID = 1364452487330669111L;
	/**
	 * 审计日志级别
	 */
	private final int level;
	/**
	 * 审计日志编码
	 */
	private final String code;
	/**
	 * 审计信息
	 */
	private final String info;
	/**
	 * 审计的目标类
	 */
	private final String targetClass;
	/**
	 * 构造函数
	 * @param level 等级
	 * @param code 编码
	 * @param info 信息
	 */
	public AuditModel(int level, String code, String info) {
		this.level = level;
		this.code = code;
		this.info = info;
		this.targetClass = "";
	}
	/**
	 * 构造函数
	 * @param level 等级
	 * @param code 编码
	 * @param info 信息
	 * @param targetClass 审计目标类
	 */
	public AuditModel(int level, String code, String info, String targetClass) {
		this.level = level;
		this.code = code;
		this.info = info;
		this.targetClass = targetClass;
	}
	public int getLevel() {
		return level;
	}
	public String getCode() {
		return code;
	}
	public String getInfo() {
		return info;
	}
	public String getTargetClass() {
		return targetClass;
	}
	@Override
	public String toString() {
		String format = "Audit[level:%d, code:%s, info:%s, target:%s]";
		return String.format(format, this.level, this.code, this.info, this.targetClass);
	}
	@Override
	public boolean equals(Object obj) {
		if (obj instanceof AuditModel) {
			return obj.equals(this);
		}
		if (obj instanceof String) {
			return obj.equals(this.toString());
		}
		return false;
	}
}
